//package testingActivityDeleteAfter;
//
//import java.util.List;
//
//import android.support.v4.app.FragmentManager;
//import android.os.Bundle;
//import android.support.v4.app.NavUtils;
//import android.view.MenuItem;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.Toast;
//
//import com.facebook.Session;
//import com.facebook.model.GraphUser;
//import com.facebook.widget.FriendPickerFragment;
//import com.facebook.widget.PickerFragment;
//import com.triptogether.R;
//import com.triptogether.baseclasses.BaseActivity;
//import com.triptogether.chat.fragments.ChatFragment;
//import com.triptogether.utils.androidsystem.SharedPreferencesUtils;
//import com.triptogether.utils.db.DBManager;
//import com.triptogether.utils.db.models.User;
//
//public class ChatTestingActivity extends BaseActivity {
//	
//	Button openFriendPickerButton;
//	FriendPickerFragment friendPickerFragment;
//	FragmentManager fragmentManager;
//	
//	@Override
//	public void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_testing);
//
//		openFriendPickerButton = (Button) findViewById(R.id.button_pick_friends);	    
//		
//		// Get the Fragmentmanager
//    	fragmentManager = getFragmentManager();
//    	
//    	// init the FriendPickerFragment
//    	friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.fragment_friend_picker);
//		friendPickerFragment.setMultiSelect(false);
//		
//		openFriendPickerButton.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//            	showFriendsPickerFragment();
//            }
//        });
//		
//		friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
//			@Override
//			public void onDoneButtonClicked(PickerFragment<?> fragment) {
//				// We just store our selection in the Application for other
//				// activities to look at.
//				List<GraphUser> selectedUsers = friendPickerFragment.getSelection();
//				
//				if(!selectedUsers.isEmpty()) {
//					GraphUser chosenUser = selectedUsers.get(0);
//					openFriendPickerButton.setVisibility(View.VISIBLE);
//					ChatFragment initChatFragment = createChatFragment(chosenUser);
//					
//					// Hide the FriendPicker fragment and put instead the chat fragment
//					fragmentManager.beginTransaction().hide(friendPickerFragment).commit();
//					fragmentManager.beginTransaction().replace(R.id.framelayout_chat, initChatFragment).commit();
//				} else {
//					Toast.makeText(getApplicationContext(),
//					        R.string.choose_friend_from_friend_picker, Toast.LENGTH_SHORT).show();
//				}
//			}
//		});
//	}
//	
//	@Override
//	protected void onStart() {
//	    super.onStart();
//	    
//	    // Init the UI
//	    showFriendsPickerFragment();
//	}
//	
//	private void showFriendsPickerFragment() {
//		Session activeSession = Session.getActiveSession();
//		if(!SharedPreferencesUtils.getUserLogedIn(getApplicationContext())) {
//			Toast.makeText(getApplicationContext(), R.string.login_to_app_title,
//			        Toast.LENGTH_LONG).show();
//			finish();
//		}
//		
//		if (activeSession != null && activeSession.isOpened()) {
//			fragmentManager.beginTransaction().show(friendPickerFragment).commit();
//			openFriendPickerButton.setVisibility(View.GONE);
//			friendPickerFragment.loadData(false);
//		} else {
//			Toast.makeText(getApplicationContext(), R.string.login_to_facebook_title,
//			        Toast.LENGTH_LONG).show();
//			finish();
//		}
//	}
//	
//	@Override
//	public boolean onOptionsItemSelected(MenuItem item) {
//		switch (item.getItemId()) {
//			case android.R.id.home:
//				NavUtils.navigateUpFromSameTask(this);
//				return true;
//		}
//		return super.onOptionsItemSelected(item);
//	}
//	
//	private ChatFragment createChatFragment(GraphUser user) {
//		// Get an instance DbManager
//		DBManager dbManagerInstance = DBManager.getInstance(this);
//		
//		// Try to find the user in the local DB
//		User userByFacebookId = dbManagerInstance.findUserByFacebookId(user.getId());
//		
//		// If the user does not exists, create one int the local DB.
//		if (userByFacebookId == null) {			
//			// Create User in the Local DB
//			userByFacebookId = dbManagerInstance.createUser(user.getId(), user.getName());
//		}
//		
//		// Add extra to chatFragment
//		Bundle bundle = new Bundle();
//		bundle.putString(ChatFragment.ARG_USER_ID, userByFacebookId.getFacebookId().toString());
//		
//		// Create the chatFragment and show it on the screen
//		ChatFragment chatFragment = new ChatFragment();
//		chatFragment.setArguments(bundle);
//		
//		return chatFragment;
//	}
//}
